//
//  OPHelperAccountTypeViewController.m
//  OnePiece
//
//  Created by lanou on 15/11/2.
//  Copyright © 2015年 wsy. All rights reserved.
//

#import "OPHelperAccountTypeViewController.h"
#import "OPHelperAccountTypeCell.h"

@interface OPHelperAccountTypeViewController () <UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong) NSArray *nameArray;
@property (nonatomic, strong) NSArray *moneyArray;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIButton *backBtn;
@end

@implementation OPHelperAccountTypeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.nameArray = @[@"人民币", @"港币", @"澳门币", @"新台币", @"美元", @"英镑", @"日元", @"欧元", @"韩元", @"泰铢", @"新加坡元", @"印尼盾", @"澳大利亚元", @"瑞士法郎", @"土耳其里拉", @"埃及镑", @"巴西雷亚尔", @"尼泊尔卢比", @"俄罗斯卢布", @"马尔代夫卢比"];
    self.moneyArray = @[@"CNY", @"HKD", @"MOP", @"TWD", @"USD", @"GBP", @"JPY", @"EUR", @"KRW", @"THB", @"SGD", @"IDR", @"AUD", @"CHF", @"TRY", @"EGP", @"BRL", @"NPR", @"RUB", @"MVR"];

    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64) style:(UITableViewStylePlain)];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.tableView registerClass:[OPHelperAccountTypeCell class] forCellReuseIdentifier:@"cell"];
    [self.view addSubview:_tableView];
    
    _backBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    _backBtn.frame = CGRectMake(20, 30, 40, 20);
    [_backBtn addTarget:self action:@selector(back) forControlEvents:(UIControlEventTouchUpInside)];
    [_backBtn setTitle:@"取消" forState:(UIControlStateNormal)];
    [_backBtn setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    [self.view addSubview:_backBtn];
}

- (void)back
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 20;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    OPHelperAccountTypeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    
    cell.content.text = self.nameArray[indexPath.row];
    cell.money.text = self.moneyArray[indexPath.row];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    OPHelperAccountTypeCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    self.typeBlock(cell.content.text, cell.money.text);
    [self dismissViewControllerAnimated:YES completion:nil];
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
